package codename.carrot.bomberman;

import java.io.Serializable;
import java.util.ArrayList;

import codename.carrot.bomberman.activity.LevelViewerActivity;
import codename.carrot.bomberman.game.networkobjects.DroidPoint;
import codename.carrot.bomberman.game.networkobjects.ItemContainer;

/**
 *  A class representing a level (initial positions for players, where boulders and itemcontainers are located, width and height)
 *  @see LevelReader 
 *  @see LevelViewerActivity
 * 	@author Group A4
 *
 */
public class LevelDefinition implements Serializable {
    private static final long serialVersionUID = 1L;  
    /**
      *  Represents the startposition-index  of the blue player
     */
    public final static int COLOR_BLUE=0, 
            /**
             *  Represents the startposition-index  of the yellow player
             */
            COLOR_YELLOW=1, 
            /**
             *  Represents the startposition-index  of the orange player
             */
            COLOR_ORANGE=2, 
            /**
             *  Represents the startposition-index  of the purple player
             */
            COLOR_PURPLE=3;
    /**
     *  ArrayList of positions for boulders
     */
    private ArrayList<DroidPoint> boulders;
    /**
     * ArrayList of itemContainers
     */
    private ArrayList<ItemContainer> itemContainers;
    /**
     *  The level height (number of tiles in Y-direction)
     */
    private int height,
    /**
     * The level width (number of tiles in X-direction)
     */
    width;
    /**
     * The name of this level
     */
    private String name;
    /**
     * An array of starting-positions for all players
     */
    private DroidPoint startPos[];

    /**
     * Set the array-list of boulders
     * @param boulders The array list of boulders.
     */
    public void setBoulders(ArrayList<DroidPoint> boulders) {
        this.boulders = boulders;
    }
    
    /**
     * Sets the name for this level
     * @param name  the name of this level
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     *  Returns the name for this level
     * @return  name the name of the level 
     */
    public String getName() {
        return name;
    }
    
    /**
     *  Sets the item-containers for this level
     * @param itemContainers
     */
    public void setItemContainers(ArrayList<ItemContainer> itemContainers) {
        this.itemContainers = itemContainers;
    }
    
    /**
     *  Returns a list of positions for boulders
     * @return ArrayList<DroidPoint>
     */
    public ArrayList<DroidPoint> getBoulders() {
        return boulders;
    }
    
    /**
     *  Returns a list of item-containers for this level
     * @return The list of item-containers.
     */
    public ArrayList<ItemContainer> getItemContainers() {
        return itemContainers;               
    }
       
    
    /**
     *  Sets the startposition for a specific color
     * @param color  One of the following:<ul>
     *                                 <li>{@link LevelDefinition#COLOR_BLUE}</li>
     *                                 <li>{@link LevelDefinition#COLOR_ORANGE}</li>
     *                                 <li>{@link LevelDefinition#COLOR_PURPLE}</li>
     *                                 <li>{@link LevelDefinition#COLOR_YELLOW}</li>
     *                             </ul>
     * @param pos A {@link DroidPoint}, representing starting position for <code>color</code>
     */
    public void setStartPos(int color, DroidPoint pos) {
        if(startPos == null) startPos = new DroidPoint[4];
        if(color < 0 || color > 3) return;
        startPos[color] = pos;
    }
    
    /**
     *  Returns the starting position for a color
     * @param color  One of the following:<ul>
     *                                 <li>{@link LevelDefinition#COLOR_BLUE}</li>
     *                                 <li>{@link LevelDefinition#COLOR_ORANGE}</li>
     *                                 <li>{@link LevelDefinition#COLOR_PURPLE}</li>
     *                                 <li>{@link LevelDefinition#COLOR_YELLOW}</li>
     *                             </ul>
     * @return The starting point for the player.
     */
    public DroidPoint getStartPos(int color) {
        if(color > 3 || color < 0 || startPos == null) return null;
        return startPos[color];
    }
    
    /**
     *  Returns the width of this level (number of tiles in X-direction)
     * @return number of tiles in X-direction
     */
    public int getWidth() {
        return width;
    }
    
    /**
     *  Returns the height of this level (number of tiles in Y-direction)
     * @return height the number of tiles in y-direction
     */
    public int getHeight() {
        return height;
    }
    
    /**
     *  Sets the height of this level (number of tiles in Y-direction)
     * @param height number of tiles in Y-direction
     */
    public void setHeight(int height) {
        this.height = height;
    }
    
    /**
     *  Sets the width of this level (number of tiles in X-direction)
     * @param width number of tiles in X-direction
     */
    public void setWidth(int width) {
        this.width = width;
    }
}
